#include "../mqserver/mq_exchange.hpp"
#include <gtest/gtest.h>
ns_kkymq::ExchangeManager::ptr emp;

class ExchangeTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        emp = std::make_shared<ns_kkymq::ExchangeManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        // emp->clear();
    }
};

// TEST(exchange_test,insert_test)
// {
//     std::unordered_map<std::string,std::string> map;
//     emp->declareExchange("exchange1",ns_kkymq::ExchangeType::DIRECT,true,false,map);
//     emp->declareExchange("exchange2",ns_kkymq::ExchangeType::DIRECT,true,false,map);
//     emp->declareExchange("exchange3",ns_kkymq::ExchangeType::DIRECT,true,false,map);
//     emp->declareExchange("exchange4",ns_kkymq::ExchangeType::DIRECT,true,false,map);
//     ASSERT_EQ(emp->size(),4);
// }
TEST(exchange_test,select_test)
{
    ASSERT_EQ(emp->exists("exchange1"),true);
    ASSERT_EQ(emp->exists("exchange2"),true);
    ASSERT_EQ(emp->exists("exchange3"),true);
    ASSERT_EQ(emp->exists("exchange4"),true);
    ns_kkymq::Exchange::ptr exp = emp->selectExchange("exchange2");
    ASSERT_EQ(exp->_name,"exchange2");
    ASSERT_EQ(exp->_durable,true);
    ASSERT_EQ(exp->_auto_delete,false);
    ASSERT_EQ(exp->_type,ns_kkymq::ExchangeType::DIRECT);
    ASSERT_EQ(exp->getArgs(),std::string("k1=v1&k2=v2"));
}

// TEST(exchange_test,remove_test)
// {
//     emp->deleteExchange("exchange4");
//     ns_kkymq::Exchange::ptr exp = emp->selectExchange("exchange4");
//     ASSERT_EQ(exp.get(),nullptr);
//     ASSERT_EQ(emp->exists("exchange4"),false);
// }

int main(int argc,char* argv[])
{
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new ExchangeTest);
    RUN_ALL_TESTS();
    return 0;
}